﻿/*bla bla bla check*/
using System;

namespace B13_Ex01_1
{
    public static class Program
    {
        public static void Main()
        {
            MinMax.Run();
            System.Console.WriteLine("Press Enter to Exit...");
            System.Console.ReadLine();
        }
    }

    static class MinMax
    {
        private static int m_MaxNum = 0, m_MinNum = 0, m_NumOfNumbers = 0, m_FirstNum = 0, m_SizeDividedByFirst = 0, m_SumOfNumbers = 0;
        private static float m_Average = 0;
        private static bool m_isFirstNumber = true;

        public static void Run()
        {
            getNumbersFromUser();
            printStats();
        }

        private static void getNumbersFromUser()
        {
            int currentNumber = 0;
            System.Console.WriteLine("Please enter integers. After each one press 'enter'. To Finish, enter '-1'");
            while (currentNumber != -1)
            {
                bool isValid = int.TryParse(System.Console.ReadLine(), out currentNumber);
                if (isValid && currentNumber > 0)
                {
                    updateStats(currentNumber);
                }
                else
                {
                    if (currentNumber != -1)
                    {
                        System.Console.WriteLine("This is not a positive integer. Please Try again:");
                    }
                }
            }
        }

        private static void updateStats(int i_CurrentNumber)
        {
            m_NumOfNumbers++;
            if (m_isFirstNumber)
            {
                m_FirstNum = i_CurrentNumber;
                m_MinNum = i_CurrentNumber;
                m_MaxNum = i_CurrentNumber;
                m_isFirstNumber = !m_isFirstNumber;
            }

            if (i_CurrentNumber < m_MinNum)
            {
                m_MinNum = i_CurrentNumber;
            }

            if (i_CurrentNumber > m_MaxNum)
            {
                m_MaxNum = i_CurrentNumber;
            }

            if ((float)(i_CurrentNumber % m_FirstNum) == 0)
            {
                m_SizeDividedByFirst++;
            }

            m_SumOfNumbers += i_CurrentNumber;
            m_Average = m_SumOfNumbers / m_NumOfNumbers;
        }

        private static void printStats()
        {
            string stats = string.Format(
@"Stats:
======
Max Number: {0}
Min Number: {1}
Num of numbers: {2}
Average: {3}
Numbers that divide with first number: {4}",
            m_MaxNum, m_MinNum, m_NumOfNumbers, m_Average, m_SizeDividedByFirst);
            System.Console.WriteLine(stats);
        }
    }
}
